package com.tiny.pong;

import java.awt.Color;
import java.awt.Graphics2D;

import com.tiny.core.game.GameObject;
import com.tiny.core.game.util.MovimentCalculator;
import com.tiny.core.input.KeyboardManager;

public class Player extends GameObject {

    private int keyUp;
    private int keyDown;

    private static final int PIXELS_PER_SECONDS = 200; 

    private MovimentCalculator calc;
    public Player(int x, int y, int width, int height, int keyUp, int keyDown, MovimentCalculator calc) {
        super(x, y, width, height);
        this.keyUp = keyUp;
        this.keyDown = keyDown;
        this.calc = calc;
    }

    @Override
    public void render(Graphics2D g) {
        g.setColor(Color.WHITE);
        g.fillRect((int)pos.x, (int)pos.y, (int)pos.width, (int)pos.height);
    }

    @Override
    public void update(int currentTick) {
        if (KeyboardManager.getInstance().isHold(keyDown) && !isCollingBelow()) {
            pos.y += calc.calculate(PIXELS_PER_SECONDS);
        }

        if (KeyboardManager.getInstance().isHold(keyUp) && !isCollingAbove()) {
            pos.y -= calc.calculate(PIXELS_PER_SECONDS);
        }
    }
}
